package order

import (
	"context"

	"mall/common/jwt"
	"mall/common/resultx"
	"mall/service/forum/api/internal/svc"
	"mall/service/forum/api/internal/types"
	"mall/service/order/rpc/orderclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type RemindOrderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRemindOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RemindOrderLogic {
	return &RemindOrderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RemindOrderLogic) RemindOrder(
	req *types.IDReq,
	headers *[]*types.Header,
) (resp *types.BaseMsgResp, err error) {
	userId := jwt.GetUserId(l.ctx)
	if userId == 0 {
		return nil, resultx.NewErrCode(resultx.TOKEN_EXPIRE_ERROR)
	}

	_, err = l.svcCtx.OrderRpc.LogOrderReaction(l.ctx, &orderclient.LogReactionReq{
		UserId:  userId,
		OrderId: req.Id,
		Type:    "remind",
	})
	if err != nil {
		logx.Errorw("RemindOrder LogOrderReaction err", logx.Field("detail", err.Error()))
		return &types.BaseMsgResp{
			Msg: "操作失败",
		}, nil
	}

	return &types.BaseMsgResp{
		Msg: "操作成功",
	}, nil
}
